package com.xdja.test;

import android.util.Log;

import java.util.Iterator;
import java.util.LinkedList;

public class thz {


    private int T = 40;

    private int M = 3;

    private LinkedList<Integer> linkedList = new LinkedList();



    public int getTheOnlyOne() {
        for (int i = 1; i <= T; i ++) {
            linkedList.add(i);
        }
        int j = 1;
        int size = linkedList.size();
        while (size > 1) {
            Iterator<Integer> iterator = linkedList.iterator();
            while (iterator.hasNext()) {
                Integer next = iterator.next();
                Log.e("thz", "next valus is : " + next + " the j is :" + j);
                int result = (j % M);
                if (result == 0) {
                    Log.e("thz", "remove or kill valus is : " + next);
                    iterator.remove();
                }
                j++;
            }
            size = linkedList.size();
        }
        Integer integer = linkedList.get(0);
        Log.e("thz", "result valus is : " + linkedList.toString());
        return integer;
    }


}
